#ifndef CLOSURE_H_
#define CLOSURE_H_

#include "base/macro_def.h"

class Closure {
 public:
  virtual ~Closure() {
  }

  virtual void Run() = 0;

 protected:
  Closure() {
  }

 private:

  DISALLOW_COPY_AND_ASSIGN(Closure);
};

class StoppableClosure : public Closure {
 public:
  StoppableClosure(Closure* c)
      : exit_(false),
        c_(c) {
  }

  void Stop() {
    exit_ = true;
  }

  void Run() {
    while (!exit_) {
      c_->Run();
    }
  }

 private:
  bool exit_;
  scoped_ptr<Closure> c_;

  DISALLOW_COPY_AND_ASSIGN(StoppableClosure);
};

#endif
